// pages/doctorregister/doctorregister.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   * data为全局变量
   */
  data: {
    account: "",
    password: ""
  },
  onLoad: function (options) {
  },
  onReady: function () {
  },
  onShow: function () {
  },
  onHide: function () {
  },
  onUnload: function () {
  },
  onPullDownRefresh: function () {
  },
  onReachBottom: function () {
  },
  onShareAppMessage: function () {
  },

  accountInput: function (e) {
    this.setData({
      account: e.detail.value
    })
  },
  pwdBlur: function (e) {
    this.setData({
      password: e.detail.value
    })
    console.log(e.detail.value)
  },
  repwdBlur: function (e) {
    this.setData({
      repassword: e.detail.value
    })
    console.log(e.detail.value)
  },

  //处理register的触发事件
  register: function (e) {
    if (this.data.password != this.data.repassword) {
      wx.showModal({
        title: '提示',
        content: '两次密码输入不一致,请重新输入!',
        showCancel: false
      })
    }
    else{
    wx.request({
      url: app.globalData.url + '/API/register',
      //定义传到后台的数据
      data: {
        //从全局变量data中获取数据
        account: this.data.account,
        password: this.data.password
      },
      method: 'get',//定义传到后台接受的是post方法还是get方法
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log("调用API成功");
        wx.navigateTo({
          url: '../doctorlogin/doctorlogin'　　// 注册成功，跳转到登陆页面
        })
      },
      fail: function (res) {
        console.log("调用API失败");
      }
    })
    }
  }
})